package com.eurasia.assignment.controller.dto;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

import com.eurasia.assignment.domain.Course;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;

/**
 * 课程响应DTO
 * 用于向客户端返回课程信息
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class CourseResponse {
    private Long id;
    private String courseName;
    private String courseType;
    private Integer credit;
    private String createTime;
    private Integer selectedCount;
    private String description;
    
    private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    
    /**
     * 将领域对象转换为响应DTO
     */
    public static CourseResponse fromDomain(Course course) {
        CourseResponse response = new CourseResponse();
        response.setId(course.getId());
        response.setCourseName(course.getCourseName());
        response.setCourseType(course.getCourseType());
        response.setCredit(course.getCredit());
        response.setSelectedCount(course.getSelectedCount());
        
        // 格式化创建时间
        if (course.getCreateTime() != null) {
            response.setCreateTime(course.getCreateTime().format(FORMATTER));
        }
        
        response.setSelectedCount(course.getSelectedCount());
        response.setDescription(course.getDescription());
        
        return response;
    }
} 